//
//  ImageButton.m
//  AssistantDriving
//
//  Created by dcr on 2017/1/9.
//  Copyright © 2017年 邓兆太. All rights reserved.
//

#import "ImageButton.h"
#import "CommonUtils.h"

@implementation ImageButton

- (void)verticalImageAndTitle:(CGFloat)spacing{
    //[self setTitleColor:[UIColor grayColor] forState:UIControlStateNormal];
    //CGSize size = [CommonUtils getSizeWithString:self.titleLabel.text withFont:self.titleLabel.font withWidth:self.titleLabel.frame.size.width];
    
    self.titleLabel.textAlignment = NSTextAlignmentCenter;
    self.imageView.contentMode = UIViewContentModeScaleAspectFit;
    self.contentVerticalAlignment = UIControlContentVerticalAlignmentBottom;
    self.contentHorizontalAlignment = UIControlContentHorizontalAlignmentCenter;
    //CGFloat left = -(self.frame.size.width/2+size.width/2);
    //self.titleEdgeInsets = UIEdgeInsetsMake(0, left, -(self.frame.size.height/2+spacing), 0);
    
    //self.titleEdgeInsets = UIEdgeInsetsMake(0, 0, -(self.frame.size.height/2+spacing), 0);
    //self.imageEdgeInsets = UIEdgeInsetsMake(0, 0, 0, 0);
    
    
    CGSize imageSize = self.imageView.frame.size;
    CGSize titleSize = self.titleLabel.frame.size;
    
    CGFloat totalHeight = (imageSize.height + titleSize.height + spacing);
    //self.imageEdgeInsets = UIEdgeInsetsMake( - (totalHeight - imageSize.height), 0.0, 0.0, - titleSize.width);
    //self.titleEdgeInsets = UIEdgeInsetsMake( 0.0, - imageSize.width, - (totalHeight - titleSize.height), 0.0);
    
    self.imageEdgeInsets = UIEdgeInsetsMake(-spacing, 0.0,0.0, -self.titleLabel.bounds.size.width);
    self.titleEdgeInsets = UIEdgeInsetsMake(self.imageView.frame.size.height ,-self.imageView.frame.size.width, -spacing,0.0);
    
    
    //[self setTitleEdgeInsets:UIEdgeInsetsMake(self.imageView.frame.size.height+10 ,-self.imageView.frame.size.width, 0.0,0.0)];//文字距离上边框的距离增加imageView的高度，距离左边框减少imageView的宽度，距离下边框和右边框距离不变
    
    //[self setImageEdgeInsets:UIEdgeInsetsMake(-10, 0.0,0.0, -self.titleLabel.bounds.size.width)];//图片距离右边框距离减少图片的宽度，其它不边
}

@end
